package com.example.wechat;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public  class Myadaptr extends RecyclerView.Adapter<Myadaptr.MyViewHolder> {
    private View view;
    private Context context;
    private List<String> list_name,list_vale,img_name;
    //是根据viewType返回布局ID。
    public Myadaptr(Context context, List<String> list_name,List<String> list_vale,List<String> img_name) {
        this.context = context;
        this.list_name = list_name;
        this.list_vale=list_vale;
        this.img_name=img_name;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view= LayoutInflater.from(context).inflate(R.layout.item,parent,false);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.item_name.setText(list_name.get(position));
        holder.item_vale.setText(list_vale.get(position));
        holder.imageView.setImageResource(R.drawable.wallhaven2ejeo6);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,itemActivity.class);
                context.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return list_name==null?0:list_name.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView item_name;
        private TextView item_vale;
        private ImageView imageView;
        public MyViewHolder(@NonNull View view){
            super(view);
            item_name= view.findViewById(R.id.item_name);
            item_vale=view.findViewById((R.id.item_vale));
            imageView=view.findViewById(R.id.imageView);
        }
    }
}
